import Cars.Car;
import Cars.ICarFactory;

import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {

        //System.out.printf("Hello and welcome!");
        System.out.println(ReadClassNameFromXML());

        try {
            ICarFactory factory;


            Class classReflection =
                    Class.forName(ReadClassNameFromXML());
            Object objcetReflection = classReflection.newInstance();


            factory = (ICarFactory) objcetReflection;
            Car car = factory.carFactoryMethod();
            System.out.printf(car.showInfo());
        }catch (Exception ex){
            System.out.println(ex.getMessage());
        }






    }

    public static String ReadClassNameFromXML(){

        String className = "";
        try{

            DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = dFactory.newDocumentBuilder();
            Document doc;
            doc = builder.parse(new File("src//config.xml"));

            NodeList nl = doc.getElementsByTagName("className");
            Node classNode=nl.item(0).getFirstChild();
            className=classNode.getNodeValue();


        }catch (Exception ex){
            ex.printStackTrace();

        }finally {

        }
        return className;



    }
}